package com.sky.controller.common;

import com.sky.dto.CategoryDTO;
import com.sky.dto.CategoryPageQueryDTO;
import com.sky.pojo.Category;
import com.sky.result.PageResult;
import com.sky.result.Result;
import com.sky.service.common.CategoryService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 菜品分类业务控制器
 *
 * @Author: Zhy
 * @Date: 2025-01-15 17:22
 * @Version: 1.0
 */
@RestController
@RequestMapping("/admin/category")
@Api(tags = "分类相关接口")
@Slf4j
@RequiredArgsConstructor
public class CategoryController {
	private final CategoryService categoryService;

	/**
	 * 新增分类
	 *
	 * @return:
	 * @param:
	 */
	@PostMapping
	@ApiOperation("新增分类")
	public Result<String> save(@RequestBody CategoryDTO categoryDTO) {
		log.info("新增分类：{}", categoryDTO);

		return categoryService.saveCategory(categoryDTO);
	}

	/**
	 * 分类分页查询
	 *
	 * @return:
	 * @param:
	 */
	@GetMapping("/page")
	@ApiOperation("分类分页查询")
	public Result<PageResult> page(CategoryPageQueryDTO categoryPageQueryDTO) {
		log.info("分页查询：{}", categoryPageQueryDTO);

		return categoryService.selectPageQuery(categoryPageQueryDTO);
	}

	/**
	 * 删除分类
	 *
	 * @return:
	 * @param:
	 */
	@DeleteMapping
	@ApiOperation("删除分类")
	public Result<String> deleteById(Long id) {
		log.info("删除分类：{}", id);

		return categoryService.deleteById(id);
	}

	/**
	 * 修改分类
	 *
	 * @return:
	 * @param:
	 */
	@PutMapping
	@ApiOperation("修改分类")
	public Result<String> update(@RequestBody CategoryDTO categoryDTO) {
		log.info("修改分类：{}", categoryDTO);

		return categoryService.updateCategoryById(categoryDTO);
	}

	/**
	 * 启用、禁用分类
	 *
	 * @return:
	 * @param:
	 */
	@PostMapping("/status/{status}")
	@ApiOperation("启用禁用分类")
	public Result<String> startOrStop(@PathVariable("status") Integer status, Long id) {
		log.info("启用禁用分类：{}，{}", status, id);

		return categoryService.startOrStop(status, id);
	}

	/**
	 * 根据类型查询分类
	 *
	 * @return:
	 * @param:
	 */
	@GetMapping("/list")
	@ApiOperation("根据类型查询分类")
	public Result<List<Category>> list(Integer type) {
		log.info("根据类型查询分类：{}", type);

		return categoryService.selectByCategoryType(type);
	}
}
